﻿#include "./object.h"

using namespace std;
using namespace MiniUI;

Object::Object(const char* szType)
: m_szType(szType)
, m_ref(1)
{
}

Object::~Object()
{
}

int Object::AddRef()
{
    return ++m_ref;
}

int Object::Release()
{
    m_ref--;
    int tmp = m_ref;
    if (m_ref == 0)
    {
        delete this;
    }
    return tmp;
}

const char* Object::GetType() const
{
    return m_szType;
}

bool Object::CheckType(const char* szType) const
{
    return (szType == m_szType);
}

ObjectGuard::ObjectGuard(const Object* pObj)
{
    m_pObj = const_cast<Object*>(pObj);
    m_pObj->AddRef();
}

ObjectGuard::~ObjectGuard()
{
    m_pObj->Release();
}